package cn.xiaolang.function.recursion;

import java.util.LinkedList;
import java.util.List;

/**
 * 递归实现：排列组合
 * 给定字符串数组：{"1" "2" "3"}
 * 组合结果：1,2,3,12,13,23,123 六种情况
 * @author Xiaolang
 */
public class ArrayCombination {

    private static int count = 1;
    /**
     * 排列组合
     * @param list 进行排列组合的集合
     * @param str  排列组合的结果
     * @param size 要排列集合的大小
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void combination(List list,String str,int size){
        if(size == str.length()){
            System.out.println("第"+count+"个：" + str);
            count++;
        }
        for (int i = 0; i < list.size(); i++) {
            List second = new LinkedList(list);
            combination(second, str+second.remove(i),size);
        }

    }


    
    public static void main(String[] args) {
        String[] strs = new String[]{"1","2","3","4"}; 
//        System.out.println(strs.length);
//        System.out.println(Arrays.asList(strs).size());
//        System.out.println("字符串数组："+StringUtils.join(strs,"")+",排列组合的结果为：");
//        //把字符串数组转换为集合，进行组合排序
//        combination(Arrays.asList(strs), "",strs.length);



        String str="abcde";
        StringBuffer strb=new StringBuffer();
        int len=str.length();
        for(int i=0;i<len;i++){
            for(int j=i+1;j<len;j++){
                strb.append(str.charAt(i));
                strb.append(str.charAt(j)+" ");
                strb.append(str.charAt(j));
                strb.append(str.charAt(i)+" ");
            }
        }

        System.out.println(strb.toString());
    }
    
    
}
